// import myBaseurl from '@/api/hostRequest.js'
// 可以从外部引入baseURL,也可以定义到config下的baseURL中
// const baseUrl = 'http://139.196.240.82/api/'
// const baseUrl = 'https://www.cqdxl.com/api/'
const baseUrl = 'https://beer.yy.hk.cn/'
export const myRequest = (url, method, data) => {
	return new Promise((resolve, reject) => {
		uni.showLoading({
			title: '加载中'
		})
		uni.request({
			url: baseUrl + url,
			method: method,
			data: data,
			header: {
				'Authorization': 'Bearer ' + uni.getStorageSync('userToken') || ''
			},
			sslVerify: false,
			success: (res) => {
				console.log(res);
				if (res.data.status == 200) {
					resolve(res.data)
				} else if (res.data.status == 410000) {
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/index/login',
						})
					}, 1500)
				} else if (res.data.status == 410001) {
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/index/login',
						})
					}, 1500)
				} else {
					uni.$u.toast(res.data.msg)
				}
			},
			fail: (err) => {
				reject(err);
			},
			complete: res => {
				uni.hideLoading()
			}
		});
	});
};